package com.niuxiaofa.newlaw.adapter;

import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Bean.QueryVideoListByLableBean;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class CourseAdapter extends RecyclerView.Adapter<CourseAdapter.ViewHolder> {
    public List<QueryVideoListByLableBean.DataDTO.RecordsDTO> listEntities;
    SharedPreferences sharedPreferences;
    Onclick onclick;



    public CourseAdapter(List<QueryVideoListByLableBean.DataDTO.RecordsDTO> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }


    @Override
    public ViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_course, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( ViewHolder viewHolder, int i) {

        QueryVideoListByLableBean.DataDTO.RecordsDTO listEntity = listEntities.get(i);

        GlideUtils.loadRoundedImage(UIUtils.getContext(), listEntity.getCourseCoverPicUrl(), viewHolder.courseCoverPicUrl);

        viewHolder.courseName.setText(listEntity.getCourseName());

        viewHolder.relativelayout.setOnClickListener(e->{
            onclick.onclick(i);
        });




    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {


        @BindView(R.id.courseCoverPicUrl)
        ImageView courseCoverPicUrl;

        @BindView(R.id.courseName)
        TextView courseName;

        @BindView(R.id.hot)
        TextView hot;


        @BindView(R.id.relativelayout)
        RelativeLayout relativelayout;


        public ViewHolder( View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
